package com.shy.config.handler;

import com.shy.config.common.BusinessEnum;
import com.shy.config.model.R;
import com.shy.config.util.ResponseUtils;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.web.access.AccessDeniedHandler;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * 权限认证处理器
 */
@Component
public class AccessDeniedHandlers implements AccessDeniedHandler {
    @Override
    public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException accessDeniedException) throws IOException, ServletException {
        /*响应数据给前端*/
        ResponseUtils.write(response, R.failure(BusinessEnum.TOKEN_NOT_PERMISSION));
    }
}
